//
// Created by jie.jiang on 2022/9/20.
//

#ifndef FOC_AS5600_H
#define FOC_AS5600_H

#include "main.h"

#define I2C_ADDRESS (0x36<<1)
#define RADIAN_PER_COUNTER  0.012271846303  //2pi*pn/2^12

typedef enum
{
    _ams5600_Address = 0x36,
    _zmco = 0x00,
    _zpos_hi = 0x01,
    _zpos_lo = 0x02,
    _mpos_hi = 0x03,
    _mpos_lo = 0x04,
    _mang_hi = 0x05,
    _mang_lo = 0x06,
    _conf_hi = 0x07,
    _conf_lo = 0x08,
    _raw_ang_hi = 0x0c,
    _raw_ang_lo = 0x0d,
    _ang_hi = 0x0e,
    _ang_lo = 0x0f,
    _stat = 0x0b,   //status reg
    _agc = 0x1a,
    _mag_hi = 0x1b,
    _mag_lo = 0x1c,
    _burn = 0xff
}AMS5600Registers_t;

#define SENSOR_VALUE_RANGE 4095

void AS5600_Init(void);
uint8_t AS5600_detectMagnet(void);
uint16_t AS5600_getRawData(void);
float AS5600_getRawAngle(void);
void angleUpdate(void);
float AS5600_getFullAngle(void);
float AS5600_getLapAngle();
float getVelocity(void);

#endif //FOC_AS5600_H
